import 'package:common_widgets/textfield/clear_textfield_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

/*
 * @author[hansen]
 * @version[创建日期，2022/5/27 18:10]
 * @function[文本-输入框]
 */

class TextClearTextFieldLayout extends StatelessWidget {
  final String? text;
  final String? arrowText;
  final String? hintText;
  final String? counterText;
  final TextStyle? textStyle;
  final TextStyle? arrowTextStyle;
  final TextStyle? hintStyle;
  final TextAlign? arrowTextAlign;
  final int? arrowMaxLines;
  final int? arrowMaxLength;
  final double space;
  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;
  final TextEditingController? controller;
  final List<TextInputFormatter>? inputFormatters;
  final TextInputType? keyboardType;
  final CrossAxisAlignment crossAxisAlignment;
  final bool? showClearIcon;

  const TextClearTextFieldLayout({
    Key? key,
    this.text,
    this.arrowText,
    this.hintText,
    this.counterText,
    this.textStyle,
    this.arrowTextStyle,
    this.hintStyle,
    this.arrowTextAlign,
    this.arrowMaxLines,
    this.arrowMaxLength,
    this.space = 20,
    this.padding,
    this.margin,
    this.controller,
    this.inputFormatters,
    this.keyboardType,
    this.showClearIcon,
    this.crossAxisAlignment = CrossAxisAlignment.center,
  })  : assert(text != null),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: margin,
      padding: padding ?? const EdgeInsets.fromLTRB(15, 10, 15, 10),
      child: Row(
        crossAxisAlignment: crossAxisAlignment,
        children: [
          Text(
            text.toString(),
            style: textStyle ??
                const TextStyle(
                  color: Color(0xFF909399),
                  fontSize: 14,
                ),
          ),
          SizedBox(
            width: space,
          ),
          Expanded(
            child: ClearTextFieldWidget(
              textStyle: arrowTextStyle ??
                  const TextStyle(
                    color: Color(0xFF303133),
                    fontSize: 14,
                  ),
              textAlign: arrowTextAlign ?? TextAlign.start,
              maxLines: arrowMaxLines ?? 1,
              maxLength: arrowMaxLength,
              controller: controller,
              inputFormatters: inputFormatters,
              keyboardType: keyboardType,
              inputBorder: InputBorder.none,
              counterText: counterText,
              hintText: hintText,
              hintStyle: hintStyle ??
                  const TextStyle(
                    color: Color(0xFFC0C4CC),
                  ),
            ),
          )
        ],
      ),
    );
  }
}
